# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/26 下午1:40
 @Author  : tgy

 https://leetcode-cn.com/problems/add-two-numbers/
"""
from ListNode import ListNode

def addTwoNumbers(l1: ListNode, l2: ListNode) -> ListNode:
    ...

    next_val = 0
    dummy_node = ListNode(0)
    tail_node = dummy_node

    while l1:
        val = l1.val + next_val
        if l2:
            val += l2.val
            l2 = l2.next
        tail_node.next = ListNode(val % 10)
        next_val = val / 10
        tail_node = tail_node.next
        l1 = l1.next

    while l2:
        val = l2.val + next_val
        tail_node.next = ListNode(val % 10)
        tail_node = tail_node.next
        next_val = val / 10
        l2 = l2.next

    if next_val:
        tail_node.next = ListNode(next_val)

    return dummy_node.next


if __name__ == '__main__':
    ...
